package com.yh.csx.bsf.flow.web.controller;

import ch.qos.logback.core.db.DBHelper;
import com.yh.csx.bsf.core.util.PropertyUtils;
import com.yh.csx.bsf.flow.core.db.DbHelper;
import com.yh.csx.bsf.flow.dao.dal.t_user_dal;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.alibaba.fastjson.JSON;
import com.yh.csx.bsf.flow.web.base.User;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping("/")
public class HomeController {
	
    @RequestMapping("/")
    public String index()
    {
        return "/home/index";
    }
    /**
     * 登录页面
     * */
    @RequestMapping(value="/login",method=RequestMethod.GET)
    public String login_page()
    {
        return "/home/index";
    }
    /**
     * 登录
     * */
    @RequestMapping(value="/login.do",method=RequestMethod.POST)
    public String login(String username,String password)
    {
    	if(PropertyUtils.getPropertyCache("flow.userno","").equals(username)&&
        PropertyUtils.getPropertyCache("flow.password","").equals(password))
    	{//登录成功
            val user = DbHelper.noTransactionGet((c)->{
                return new t_user_dal().getByNo(c,PropertyUtils.getPropertyCache("flow.userno",""));
            });
            if(user!=null) {
                User u = new User(user.name, user.no, user.email, user.mobile);
                User.setCurrent(u);
                //return "redirect:user/flow/lunched_list";
                return "redirect:/manager/flow/index";
            }
    	}
    	//log.info("登录信息："+JSON.toJSONString(reponse));
    	return "/home/index";
    }
    
    @RequestMapping(value="/logout",method=RequestMethod.GET)
    public String logout()
    {
    	User.setCurrent(null);
        return "/home/index";
    }
}
